home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Bus / A / Acius08⁄92.cpt / Acius08_92 / Encoding_Decipheringƒ / Sources / EncryptPicture.a < prev    next >
Text File  |  1992-08-17  |  4KB  |  127 lines

  1. ;
  2. ; Encoding pictures external routine for 4D
  3. ; written by François Marchal, © ACI 1992
  4. ; Parameters :
  5. ; -> Picture to encode
  6. ; -> Longint key word (you need the same key to encode and to decipher the picture)
  7. ;
  8.  
  9.     CASE    OBJ
  10.     INCLUDE 'traps.a'
  11.     
  12. picsize            EQU        104
  13. cle                EQU        100
  14. signature        EQU        98
  15. masignature        EQU        $464D
  16. picend            EQU        6
  17.  
  18.     EXPORT        EncryptPicture
  19.  
  20. EncryptPicture    PROC         
  21.     CODE
  22.  
  23.     LINK        A6,#$0
  24.     MOVEM.L        D4-D7/A4,-(A7)            ; save the used registers
  25.     MOVEA.L        12(A6),A4
  26.     MOVE.L        (A4),A4                    ; A4 : Handle on the picture to encode
  27.     BEQ            Fini                    ; if the Handle passed is Nil, don't do anything
  28.  
  29.     MOVE.L        (A4),A0    
  30.     MOVE.W        signature(A0),D0
  31.     CMPI.W        #masignature,D0            ; verify if the handle hasn't been signed
  32.     BEQ            fini                    ; if the picture has already been encoded, don't do anything
  33.     
  34.  
  35.     MOVE.L        A4,A0
  36.     _GetHandleSize
  37.     MOVE.L        D0,D7                    ; store the size of the Handle in D7
  38.     BEQ.S        Fini                    ; If the Handle is empty, stop
  39.  
  40.     MOVE.L        A4,A0                    ; to insert the lock here
  41.     ADD.L        #picsize,D0                ; make the Handle as big as the size of the new picture
  42.     _SetHandleSize
  43.     MOVE.W        D0,D0
  44.     BMI.S        Fini
  45.     
  46.     SUBQ.L        #picend,D7
  47.     MOVE.L        (A4),A0
  48.     ADDA.L        D7,A0                    ; move the 6 bytes from the picend 
  49.     MOVEA.L        A0,A1                    ; to the end of the block
  50.     ADDA.L        #picsize,A1
  51.     MOVE.L        (A0)+,(A1)+
  52.     MOVE.W        (A0)+,(A1)    
  53.                                         ; take the old header of the picture and place it at the end of the block
  54.     MOVE.L        (A4),A0                    ; Source -> move the pointer to the beginning of the data
  55.     MOVE.L        A0,A1                    ; Dest   -> calculate a pointer to the end of the data
  56.     ADDA.L        D7,A1                    ; 
  57.     MOVE.L        #picsize,D0                ; Lenght -> the size of the header
  58.     _BlockMove                            ; move the header to the end of the block
  59.  
  60.     LEA            Verrou,A0                ; Source -> take the address of the data of the lock
  61.     MOVE.L        (A4),A1                    ; Dest   -> take the Handle dereferened
  62.     MOVE.L        #picsize,D0                ; Lenght -> number of bytes to move
  63.     _BlockMove                            ; place our own header at the beginning of the picture
  64.     
  65.  
  66.     MOVE.L        8(A6),A0                ; dereferencing (parameter passed in var)
  67.     MOVE.L        (A0),D4                    ; of the encoding key
  68.     MOVE.L        (A4),A0                    ; saving of the key after the signature
  69.     MOVE.L        D4,Cle(A0)                ;
  70.  
  71.     MOVE.L        (A4),A0
  72.     ADDA.L        #Picsize,A0                ; A0 : pointer to the data to encode
  73.  
  74.     MOVE.L        D7,D6
  75.     ANDI.L        #$1F,D6                    ; D6 -> the remainder of the whole division of D7 by 32
  76.  
  77.     LSR.L        #5,D7                    ; divide by 32 of the size of the Handle
  78.     BEQ.S        GereReste                ; allows us to know the number of passes in the loop
  79.  
  80.     SUBQ        #1,D7                    ; take 1 to D7 for the dbra
  81.  
  82. Loop:
  83.     MOVE.L        D4,D5
  84.     SUB.L        D7,D5
  85.     EOR.L        D5,(A0)+                ; 1
  86.     EOR.L        D5,(A0)+                ; 2
  87.     EOR.L        D5,(A0)+                ; 3
  88.     EOR.L        D5,(A0)+                ; 4
  89.     EOR.L        D5,(A0)+                ; 5
  90.     EOR.L        D5,(A0)+                ; 6
  91.     EOR.L        D5,(A0)+                ; 7
  92.     EOR.L        D5,(A0)+                ; 8 x 4 = 32 bytes processed by the loop
  93.     
  94.     DBRA        D7,Loop                    
  95.  
  96. GereReste:                                ; take care of the remaining bytes
  97.     CMPI.L        #0,D6
  98.     BLE.s        Fini
  99.     EOR.B        D6,(A0)+
  100.     SUBQ        #1,D6
  101.     BRA.S        GereReste
  102.     
  103. Fini:    
  104.     MOVEM.L        (A7)+,D4-D7/A4            ; restoring the registers
  105.     UNLK        A6
  106.     MOVEA.L        (A7)+,A0                ; read the return address
  107.     ADDQ.L        #$8,A7                    ; take the parameters off of the stack
  108.     JMP            (A0)                    ; and return to the calling point
  109.  
  110. Verrou:    
  111.     DC.B        $00,$61,$00,$00,$00,$00,$00,$10,$00,$10        ; lock picture
  112.     DC.B        $11,$01,$A0,$00,$82,$A0,$00,$8E,$01,$00
  113.     DC.B        $0A,$00,$00,$00,$00,$00,$10,$00,$10,$90
  114.     DC.B        $00,$02,$00,$52,$00,$7E,$00,$62,$00,$8E
  115.     DC.B        $00,$52,$00,$7E,$00,$62,$00,$8E,$00,$00
  116.     DC.B        $00,$00,$00,$10,$00,$10,$00,$00,$00,$00
  117.     DC.B        $07,$C0,$0F,$E0,$1C,$70,$18,$30,$18,$30
  118.     DC.B        $18,$30,$3F,$F8,$3F,$F8,$3C,$78,$3C,$78
  119.     DC.B        $3E,$F8,$3E,$F8,$3F,$F8,$3F,$F8,$00,$00
  120.     DC.B        $A0,$00,$8F,$A0,$00,$83,$FF,$00
  121.  
  122.     DC.W        masignature
  123.     DC.L        $0
  124.     
  125.     ENDP    
  126.     END